package com.example.wemedia.controller;

import com.example.wemedia.service.WmNewsService;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmNewsDto;
import com.usian.model.media.dtos.WmNewsPageReqDto;
import com.usian.model.media.dtos.WmUserDto;
import com.usian.model.media.pojos.WmNews;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api
@RequestMapping("wemedia/news/v1")
@RestController
public class WmNewsController {
    
    @Autowired
    private WmNewsService wmNewsService;
    
    
    /**
     * 自媒体查询
     *
     * @param wmNewsPageReqDto wm新闻页面要求的dto
     */
    @PostMapping("/get_all_news")
    public ResponseResult getAllNew(WmNewsPageReqDto wmNewsPageReqDto) {
        return wmNewsService.getAllNew(wmNewsPageReqDto);
    }
    
    
    /**
     * 提交
     *
     * @param wmNewsDto wm新闻dto
     * @throws Exception 异常
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto) throws Exception {
        //String content = wmNewsDto.getContent();
        //
        return wmNewsService.submit(wmNewsDto);
    }
    
    
    /**
     * 添加wm用户
     *
     * @param wmUserDto wm用户dto
     */
    @PostMapping("/add_wm_user")
    public ResponseResult addWmUser(@RequestBody WmUserDto wmUserDto) {
        wmNewsService.addWmUser(wmUserDto);
        return ResponseResult.okResult(200, "成功");
    }
    
    /**
     * 得到自媒体文章信息通过id
     *
     * @param id id
     * @return {@code WmNews}
     */
    @GetMapping("/get_wm_news_by_id")
    public WmNews getWmNewsById(Integer id) {
        return wmNewsService.getWmNewsById(id);
    }
    
    /**
     * 更新wm新闻通过id
     *
     * @param wmNews wm新闻
     * @return {@code Integer}
     */
    @PostMapping("/update_wm_news_by_id")
    public Integer updateWmNewsById(@RequestBody WmNews wmNews) {
        return wmNewsService.updateWmNewsById(wmNews);
    }
    
}
